package com.redoor.app.stake.basicdata.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.redoor.app.stake.basicdata.model.BaseRegistration;
import com.redoor.app.stake.basicdata.model.controllerModel.BaseRegistrationCriteria;
import com.redoor.app.stake.basicdata.model.serviceModel.BaseRegistrationServiceBean;
import com.redoor.app.stake.basicdata.service.BaseRegistrationService;
import com.redoor.app.stake.common.model.Page;
import com.redoornetwork.framework.core.response.ResponseResult;
import com.redoornetwork.framework.core.response.ResultGenerator;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* Created by wangjunlei on 2018-03-09 10:22:50.
*/
@RestController
@RequestMapping("/base/registrations")
public class BaseRegistrationController {

    @Autowired
    private BaseRegistrationService baseRegistrationService;

    @PostMapping
    public ResponseResult add(@RequestBody BaseRegistration baseRegistration) {
        baseRegistrationService.save(baseRegistration);
        return ResultGenerator.generatorSuccess();
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable String id) {
        baseRegistrationService.deleteById(id);
        return ResultGenerator.generatorSuccess();
    }

    @PutMapping
    public ResponseResult update(@RequestBody BaseRegistration baseRegistration) {
        baseRegistrationService.updateBySelective(baseRegistration);
        return ResultGenerator.generatorSuccess();
    }
    @ApiOperation(value = "注册码详情,传入id='主键'")
    @PostMapping("/detail")
    public ResponseResult detail(@PathVariable String id) {
        BaseRegistration baseRegistration = baseRegistrationService.findById(id);
        return ResultGenerator.generatorSuccess(baseRegistration);
    }
    /**
     * 注册码查询页面
     * @Author zhangYiHang
     * @Date 2018/3/16 13:24
     */
    @ApiOperation(value = "查询所有注册码", notes = "查询所有注册码")
    @RequiresPermissions("base:registcode:list")
    @GetMapping("/list")
    public ResponseResult list(BaseRegistrationCriteria criteria) {
        List<BaseRegistrationServiceBean> list = this.baseRegistrationService.qryRegistrationList(criteria);
        int total = this.baseRegistrationService.qryRegistrationTotal(criteria);
        Page pageInfo = new Page();
        pageInfo.setTotal(total);
        pageInfo.setData(list);
        return ResultGenerator.generatorSuccess(pageInfo);
    }

}
